﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace ServerService
{
    public partial class Service1 : ServiceBase
    {
        //[DllImport("server.exe")]
        //private static extern int run();

        public Service1()
        {
            InitializeComponent();
        }

        protected System.Diagnostics.Process m_server;
        protected override void OnStart(string[] args)
        {
            // TODO: 在此处添加代码以启动服务。
            //Console.Beep(1000,100);
            m_server = Process.Start("c:\\nudota_server");
            //this.EventLog.WriteEntry(Directory.GetCurrentDirectory());            
        }

        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            //Console.Beep(500, 100);
            try
            {
                m_server.Kill();
            }
            catch (Exception e)
            {
                EventLog.WriteEntry(e.Message);
            }
            m_server = null;
        }
    }
}
